package me.jiatao.wan.model

import androidx.recyclerview.widget.DiffUtil
import me.jiatao.wan.AppConfig
import me.jiatao.wan.common.ext.getEmptyOrDefault

/**
 * @Author: taojia
 * @CreateDate: 2021/8/27 5:24 下午
 * @Version: 1.0
 * @Description:
 */

data class ArticleModel(
    val id: Int,
    val author: String,
    val niceDate: String,
    val title: String,
    val envelopePic: String,
    val isTop: Boolean,
    val superChapterName: String,
    val chapterName: String,
    val isCollect: Boolean,
    val link: String
) {
    companion object {
        val diffCallback = object : DiffUtil.ItemCallback<ArticleModel>() {
            override fun areItemsTheSame(
                oldItem: ArticleModel,
                newItem: ArticleModel
            ): Boolean {
                return oldItem.id == newItem.id && oldItem.title == newItem.title
            }

            override fun areContentsTheSame(
                oldItem: ArticleModel,
                newItem: ArticleModel
            ): Boolean = oldItem == newItem

        }
    }

    fun getFinalAuthor(): String {
        return author.getEmptyOrDefault {
            "未知作者"
        }
    }

    val userAvatar: String
        get() {
            return AppConfig.getPlaceImg(author)
        }
}